package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IHomePageContentFragmentModle;
import com.wgts.wgts.mvp.presenter.IHomePageContentFragmentPersenter;
import com.wgts.wgts.mvp.view.IHomePageContentFragmentView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.req.ActivityListRequest;
import com.wgts.wgts.netmodle.req.AppModleRequest;
import com.wgts.wgts.netmodle.resp.ActivityListEntity;
import com.wgts.wgts.netmodle.resp.AppModleEntity;
import com.wgts.wgts.netmodle.resp.VipMessageEntity;
import com.wgts.wgts.rxjava.MVPResultSubscriber;

import java.util.List;

public class HomePageContentFragmentPersenter implements IHomePageContentFragmentPersenter {

    private IHomePageContentFragmentView view;

    private IHomePageContentFragmentModle modle;

    public HomePageContentFragmentPersenter(IHomePageContentFragmentView view, IHomePageContentFragmentModle modle) {
        this.view = view;
        this.modle = modle;
    }

    @Override
    public void initDataView() {
        AppModleRequest appModleRequest = new AppModleRequest();
        appModleRequest.scene = "0";
        appModleRequest.parentTypeId = -1;
        modle.initDataView(appModleRequest, new HttpResultSubscriber<List<AppModleEntity>>() {
            @Override
            public void onSuccess(List<AppModleEntity> appModleEntities) {
                view.initResult(appModleEntities);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void toastVipMessage() {
        modle.startCutDown(new MVPResultSubscriber<VipMessageEntity>() {
            @Override
            public void netx(VipMessageEntity message) {
                view.toastVipMessage(message);
            }
        });
    }

    @Override
    public void stopCutDown() {
        modle.removeCutDown();
    }

    @Override
    public void timeActionList() {
        ActivityListRequest request = new ActivityListRequest();
        request.activityType = "FLASH_SALE";
        modle.timeActionList(request, new HttpResultSubscriber<List<ActivityListEntity>>() {
            @Override
            public void onSuccess(List<ActivityListEntity> entities) {
                view.actionistResult(entities);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void vipMessage() {
        modle.vipMessage(new HttpResultSubscriber<List<VipMessageEntity>>() {
            @Override
            public void onSuccess(List<VipMessageEntity> vipMessageEntities) {
                view.vipMessage(vipMessageEntities);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }


}
